<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
    <head th:replace="~{common/header :: common_header(~{::title},~{::link},~{})}">
        <title>git跨分支搜索工具</title>
    </head>
<body>
    <div class="container">
        <div style="padding-top:50px;">
            本地索引路径： <span th:text="${lucene_directory}"></span>
            <a style="margin-left: 50px;" th:href="@{'/createIndex'}">建索引</a>
            <a style="float:right" th:href="@{'/gotoAdd'}">增加项目</a>
        </div>
        <div >想要获取全部分支的提交记录需要现在git本地仓库执行命令</div>
        <div>            
            <pre>
            1. 手动更新代码
            git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
            # 验证本地分支情况
            git branch 
            # 创建索引之前可以通过命令checkout每个分支并pull到最新
            git branch | grep -v '\->' | while read br; do git checkout  "$br" && git pull --all; done
            2. 自动更新代码
            # 索引前自动更新代码，默认 不开启
            pull_code_before_index=false
            # git-bash.exe 路径用于执行git命令进行代码更新
            git_bash_exe=C:\\Program Files\\Git\\git-bash.exe</pre>
            
        </div>
        <div class="table-responsive">
            <table  class="table table-bordered">
                <tr>
                    <td>项目名称 </td>
                    <td>仓库路径</td>
                    <td>分支数</td>
                    <td>提交数</td>
                    <td>索引大小</td>
                    <td>索引时间</td>
                </tr>
                <tr th:each="project:${projects}">
                    <td >
                        <span th:text="${project.name}" />
                        <a th:href="@{'/deleteProject?path=' + ${project.indexpath}}">删除</a>
                    </td>
                    <td th:text="${project.path}"></td>
                    <td th:text="${project.branchs}"></td>
                    <td th:text="${project.commits}"></td>
                    <td th:text="${project.getIndexSizeStr()}"></td>
                    <td th:text="${project.getIndexTimeStr()}"></td>
                </tr>
            </table>
            <span>
                常用lucene查询语法
                布尔预算:  AND  OR  NOT  +  - , 支持 ()组合 ,例如  <code>+流程 AND (终止 OR 中止) AND bug  </code> 查询包含 流程、终止 、BUG  或者 流程、中止、bug 关键字
                多域查询:  字段: 关键字 ,例如 <code>branch:212 </code> 查询212 分支。<br>目前支持查询的索引字段有: 项目<code>project</code> ,分支<code>branch</code>,
                 提交信息<code>message</code>,提交时间<code>time</code> 作者<code>author</code>, 邮箱<code>email</code> ,修改项<code>change</code> 
            </span>
            
        </div>
        <form method="get" th:action="@{/search}"  class="searchForm">
            
            <div class="input-group" >
                <div class="input-group-addon" style="padding:0;">
                    <select name="max" id="max" class="form-control" th:value="${max}"  style="width: 60px;height: 32px;padding: 0;">
                        <option th:each="op:${options}"  th:value="${op}" th:text="${op}" th:selected="${op eq max}"></option>
                    </select>
                </div>
                <input type="search" class="form-control" th:value="${query}" name="query" placeholder="搜索提交历史">
                <span class="input-group-btn">
                    <button class="btn btn-primary" type="submit">搜索</button>
                </span>
            </div>    
            <div th:if="${timecost!=null}">
                搜索结果<span th:text="${results.size()}"></span>个,搜索耗时:<span th:text="${timecost}"></span>毫秒
            </div>
        </form>
        <address th:each="result:${results}">
            <p>
                <h3 class="md" th:attr="md=${(result.index+1) + ': ' +result.message}">commit消息</h3>
                <div class="change">
                    <div th:if="${result.get('changes')!=null}">
                        代码变动 <span class="badge" th:if="${result.changes.length > 1}" th:text="${result.changes.length}">4</span>:
                        <ol>
                            <li th:each="content:${result.changes}" th:utext="${content}">...</li>
                        </ol>
                    </div>
                    全部分支 <span class="badge" th:if="${result.branchs.length > 1}" th:text="${result.branchs.length}">4</span>:
                    <ul class="list-inline">
                        <li th:each="branch:${result.branchs}" th:attr="title=${branch}">
                            <!-- <code th:text="${branch}" style="font-size: 110%;" >Default</code> -->
                            <mark th:text="${branch}" style="font-size: 100%;" >Default</mark>
                        </li>
                    </ul>
                </div>
            </p>
            
            <footer>
                <strong th:text="${result.commitTime}"></strong>
                <strong th:text="${result.author}"></strong>(
                    <strong th:text="${result.email}"></strong>
                )
                commit: <strong th:text="${result.commitId}"></strong>
                项目：<strong th:text="${result.project}"></strong>
                 
            </footer>
        </address>
    </div>
    <style>
        .morebranch {
            display: none;
        }
        .label{
            font-size: 100%;
        }
        address{
            margin-bottom: 30px;
        }
        .searchForm{
            width:60%;
            margin-left:15%;
            margin-top:50px;
            margin-bottom:50px;
        }
    </style>
    <script>
        $(".md").each(function(){
            $(this).html(marked.parse($(this).attr('md')));
        });

    </script>
</body>
</html>